package com.sgb.member.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.member.BR;
import com.sgb.member.R;
import com.sgb.member.databinding.ItemCompanyWebAdjustmentBinding;
import com.sgb.member.entity.MemberFindPackersEntity;
import com.sgb.member.entity.MemberGoodsListEntity;
import com.sgb.member.entity.MemberLeaseBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.StringUtil;

import java.util.List;

public class CompanyWebBusinessesAdapter<T> extends BaseRecycleAdapter<T> {

    boolean isDemandMember; // 是否需方会员

    public CompanyWebBusinessesAdapter(Context context, int layoutId, List<T> datas, boolean isDemandMember) {
        super(context, layoutId, datas);
        this.isDemandMember = isDemandMember;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ItemViewHolder holder, T bean) {
        holder.setBinding(BR.itemBean, bean);
        if (bean instanceof MemberGoodsListEntity) {
            // item_company_web_adjustment
            ItemCompanyWebAdjustmentBinding binding = (ItemCompanyWebAdjustmentBinding) holder.getmBinding();
            MemberGoodsListEntity entity = (MemberGoodsListEntity) bean;
            String price;
            if (entity.isHasQuete()) {
                price = StringUtil.getPrice(String.valueOf(entity.getQuetePrice()), "元/" + entity.getUnit());
            } else {
                price = StringUtil.getPrice(String.valueOf(entity.getPrice()), "元/" + entity.getUnit());
            }
            binding.tvQuetePrice.setText(price);
        } else if (bean instanceof MemberLeaseBean) {
            // item_company_web_lease
        } else if (bean instanceof MemberFindPackersEntity) {
            // item_company_web_team
        }
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        TextView viewById = holder.itemView.findViewById(R.id.iv_member_more);
        viewById.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tModifyQuoteListener.onModifyQuote(position, datas.get(position));
            }
        });
        viewById.setVisibility(isDemandMember ? View.VISIBLE : View.GONE);
    }

    private ModifyQuoteListener<T> tModifyQuoteListener;

    public void setModifyQuoteListener(ModifyQuoteListener<T> tModifyQuoteListener) {
        this.tModifyQuoteListener = tModifyQuoteListener;
    }

    public interface ModifyQuoteListener<T> {
        void onModifyQuote(int position, T t);
    }
}
